package solution._0040._0046;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

/**
 * Created by chen_snow
 * Date: 2021/6/2 23:27
 * Description: 全排列
 */
public class Solution {
    public List<List<Integer>> permute(int[] nums) {

        List<List<Integer>> result = new ArrayList<>();
        backTrace(nums, new ArrayDeque<>(), result);
        return result;

    }

    public void backTrace(int[] nums, Deque<Integer> data, List<List<Integer>> result) {
        if (data.size() == nums.length) {
            result.add(new ArrayList<>(data));
            return;
        }

        for (int i = 0; i < nums.length; i++) {
            if (data.contains(nums[i])) {
                continue;
            }
            data.addLast(nums[i]);
            backTrace(nums, data, result);
            data.removeLast();
        }
    }
}
